<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page import="com.wxtf.platform.plugins.user.*"%>

<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
	UserBean user = (UserBean)request.getSession().getAttribute("userBean");

	String _db = user.getDbType();
%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
	<head>
		<base href="<%=basePath%>" />
		<title>个人桌面</title>
		<meta http-equiv="pragma" content="no-cache" />
		<meta http-equiv="cache-control" content="no-cache" />
		<meta http-equiv="expires" content="0" />
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />

		<link type="text/css" rel="stylesheet" href="ligerUI/skins/Aqua/css/ligerui-all.css" />
		<link type="text/css" rel="stylesheet" href="ligerUI/skins/<%=user.getUserCss()%>/css/ligerui-all.css" />
		<link type="text/css" rel="stylesheet" href="ligerUI/skins/ligerui-icons.css" />
		<link type="text/css" rel="stylesheet" href="resource/css/style.css" />

		<script type="text/javascript" src="js/jquery/jquery-1.7.2.js"></script>
		<script type="text/javascript" src="ligerUI/js/core/base.js"></script>
		<script type="text/javascript" src="ligerUI/js/ligerui.min.js"></script>
		<script type="text/javascript" src="js/common.js"></script>

		<script type="text/javascript" src="ligerUI/js/plugins/ligerGrid.js"></script>
		<script type="text/javascript" src="ligerUI/js/plugins/ligerForm.js"></script>
		
<script type="text/javascript">
var _db = '<%=_db%>';

_jsonObj.classname = "com.wxtf.platform.plugins.permissions.DesktopAction";
_jsonObj.methodname = "queryPage";

var win;
var manager;
$(function(){
	manager = $("#desktop-grid").ligerGrid({
		url: _url, parms: _jsonObj, checkbox: true,
        usePager:true, rownumbers:true, alternatingRow: true,
        enabledEdit: true, clickToEdit: false,
        width: '100%', height: '100%',pageSize:100,pageSizeOptions:[100, 150, 200],
		columns: [
			{ display: 'id', name: 'id', hide: true,width:1 },
			{ display: 'userId', name: 'userId', hide: true,width:1 },
			{ display: '菜单名称', name: 'text', width: 400, align: 'left' },
			{ display: '菜单url', name: 'action', width: 1, hide: true,align: 'left' },
			{ display: '快捷图标', name: 'quickIcon', width: 100, align: 'center',
    			render:function(record, index, value, oth){
	    			if(value == ''){
	    				return '';
	    			}
					return '<img width="16" height="16" src="' + value + '" style="padding-top: 3px;" />';
				}
        	},
			{ display: '排序号', name: 'ordernums', width: 80, align: 'right',type: 'int', editor: { type: 'int'}  },
			{ display: '编辑', name: 'id', width: 60, align: 'center',
    			render:function(record, index, value, oth){
	    			return '<a href="javascript:editData(\'' + index + '\')"  class="edit_btn_div" onmouseover="this.className=\'edit_btn_div_over\'" onmouseout="this.className=\'edit_btn_div\'"><img src="ligerUI/skins/icons/edit.gif"/></div>';
				}
        	},
			{ display: '删除', name: 'id', width: 60, align: 'center',
    			render:function(record, index, value, oth){
	    			return '<a href="javascript:delData(\'' + record.id + '\',\'' + index + '\')"  class="edit_btn_div" onmouseover="this.className=\'edit_btn_div_over\'" onmouseout="this.className=\'edit_btn_div\'"><img src="ligerUI/skins/icons/delete.gif"/></div>';
				}
        	}
		],
		isChecked: function(record, index, value, oth){
			if(record.userId != ""){
				return true;                     	     
	        }
        },
		toolbar: {
			items: [
				{ text: '保存', click: function(){ saveData(); }, icon: 'save' }
			]
		}
	});
});

/*
 * Grid页面刷新
 */
function reload(){
	_jsonObj.methodname = "queryPage";
	manager.loadData();
}

function editData(index){
	manager.select(index);
	manager.beginEdit(index);
}

/*
 * Grid页面保存、删除
 */
function saveData(){
	manager.endEdit();//提交修改
	
	var data = '[';
	var arr = manager.getUpdated();
	if(arr.length != 0){
		for(var i=0; i<arr.length; i++){
			var nums = arr[i].ordernums;
			if(Math.abs(parseInt(nums)) > 1000){
				warningTip(arr[i].text + "：排序号不能超过1000");
				return;
			}
			data += "{\"id\":\"" + arr[i].id + "\",\"num\":\"" + nums + "\"},";
		}
		data = data.substring(0, data.length - 1);
	}
	data += "]";
	
	if(data == '[]'){
		succMsgTip("没有修改，无需保存");
		return;
	}
	
	_jsonObj.methodname = "save";
	_jsonObj.logicdata = data;
	callserver(_jsonObj, function(data, satus){
		succMsgTip(data.resultrecord);
		reload();
	},function(data, satus){
		warningTip(data.resultrecord);
	});
}

/*
 * Grid页面删除
 */
function delData(id, index){
	manager.cancelEdit(index);
	
	$.ligerDialog.confirm('确定要删除选中数据吗？', function (ml) { 			
		if(ml){
			_jsonObj.methodname = "delete";
			_jsonObj.logicdata = "[{\"ids\":\"" + id + "\"}]";
			callserver(_jsonObj, function(data, satus){
				succMsgTip(data.resultrecord);
				reload();
			},function(data, satus){
				warningTip(data.resultrecord);
			});
		}
	});
}

</script>
	</head>

	<body>
		<div id="desktop-grid"></div>
		<div id="menuDiv">
			<ul id="menu-tree"></ul>
		</div>
	</body>
</html>


